package com.yaodian100.ec.cobranding.web;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.yaodian100.core.common.dao.impl.CommonCriteria;
import com.yaodian100.ec.cobranding.entity.DPNStore;
import com.yaodian100.ec.cobranding.service.DPNService;
import com.yaodian100.ec.member.entity.District;
import com.yaodian100.ec.member.service.AddessService;

/**
 * @author feeling.wang
 * 
 */
public class DPNAction extends ActionSupport implements Preparable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7199206844452992772L;
	private final Logger logger = LoggerFactory.getLogger(DPNAction.class);
	@Resource
	private DPNService dpnService;
	@Resource
	private AddessService addressService;
	private String dpnStoreCity;
	private String dpnStoreArea;
	private String dpnStoreId;
	private String dpnStoreName;
	private String comboName;
	private List<DPNStore> stores;
	private List<District> districts;
	private DPNStore dpnStrore;
	private String actionResult;

	public String dpnStore() {

		return "storelist";
	}

	public String queryStore() {
		CommonCriteria cc = new CommonCriteria();

		if (StringUtils.isNotBlank(dpnStoreCity)) {
			cc.addRlike("cityName", "%" + dpnStoreCity + "%");
			districts = addressService.getDistrictList(cc);
			setComboName("dpnStoreArea");

		}
		if (StringUtils.isNotBlank(dpnStoreArea)) {
			cc.addRlike("storeArea", "%" + dpnStoreArea + "%");
			setComboName("dpnStoreId");
			stores = dpnService.getList(0, -1, cc, null);
		}
		if (StringUtils.isNotBlank(dpnStoreId)) {
			cc.addEq("storeId", dpnStoreId);
			setComboName("dpnStoreInfo");
			dpnStrore = dpnService.getList(0, 1, cc, null).get(0);

		}

		return "dpncombo";

	}

	public String findDaphnes() throws Exception {
		if (StringUtils.isNotBlank(dpnStoreArea)) {
			CommonCriteria crit = new CommonCriteria();
			crit.addEq("storeArea", dpnStoreArea);
			List<DPNStore> DPNStores = dpnService.getDPNStoretList(crit);
			actionResult = StringUtils.defaultString(actionResult);
			for (DPNStore dpnstore : DPNStores) {
				actionResult = actionResult + dpnstore.getStoreId() + "," + dpnstore.getStoreAddress() + "("
						+ dpnstore.getStoreName() + "-" + dpnstore.getStoreType() + ")" + "," + dpnstore.getStoreLatitude() + ","
						+ dpnstore.getStoreLongitude() + "$";
			}
			if (actionResult.length() > 0) {
				actionResult = actionResult.substring(0, actionResult.length() - 1);
			}
		}
		return "jsonGetDaphnes";
	}

	public String getDpnStoreCity() {
		return dpnStoreCity;
	}

	public void setDpnStoreCity(String dpnStoreCity) {
		this.dpnStoreCity = dpnStoreCity;
	}

	public String getDpnStoreArea() {
		return dpnStoreArea;
	}

	public void setDpnStoreArea(String dpnStoreArea) {
		this.dpnStoreArea = dpnStoreArea;
	}

	public String getDpnStoreId() {
		return dpnStoreId;
	}

	public void setDpnStoreId(String dpnStoreId) {
		this.dpnStoreId = dpnStoreId;
	}

	public String getDpnStoreName() {
		return dpnStoreName;
	}

	public void setDpnStoreName(String dpnStoreName) {
		this.dpnStoreName = dpnStoreName;
	}

	public String getComboName() {
		return comboName;
	}

	public void setComboName(String comboName) {
		this.comboName = comboName;
	}

	public List<DPNStore> getStores() {
		return stores;
	}

	public void setStores(List<DPNStore> stores) {
		this.stores = stores;
	}

	public List<District> getDistricts() {
		return districts;
	}

	public void setDistricts(List<District> districts) {
		this.districts = districts;
	}

	public DPNStore getDpnStrore() {
		return dpnStrore;
	}

	public void setDpnStrore(DPNStore dpnStrore) {
		this.dpnStrore = dpnStrore;
	}

	public String getActionResult() {
		return actionResult;
	}

	public void setActionResult(String actionResult) {
		this.actionResult = actionResult;
	}

	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub

	}

}